<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<h2>Hello World!</h2>
<%
    //连接数据库
    String userName="root";
    String password="Nuist123!@#";
    String dbName="software18";
    String host="localhost";
    String port="3306";
    String url="jdbc:mysql://"+host+":"+port+"/"+dbName;
    //创建三个类
    Connection conn=null;//负责连接数据库
    Statement statement=null;//负责发送sql语句
    ResultSet rs=null;//负责查询结果
    //注册数据库驱动
    Class.forName("com.mysql.cj.jdbs.Driver");
    //连接数据库
    conn= DriverManager.getConnection(url,userName,password);
    //发送sql语句
    String sql="select * from tbl_student";
    statement=conn.createStatement();
    rs=statement.executeQuery(sql);
    //遍历结果集
    while (rs.next()){
        out.print(rs.getString("stuno")+","+rs.getString("stuname")+","+rs.getString("gender"));
        out.print("<br>");
    }
%>
</body>
</html>
